package com.com.effectivejava.commonmethods.examples;

/**
 * Created by pankaj on 7/13/14.
 */
public class Subject {

    private int id;
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    @Override
    public boolean equals(Object obj) {
        if(this == obj)
            return true;
        if(! (obj instanceof Subject))
            return false;
        Subject s = (Subject) obj;
        return this.getId() == s.getId();
    }

    @Override
    public int hashCode() {
        int result = 17;
        result = 31 * result + id;
        result =  31 * result + name.hashCode();
        return result;
    }

    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();
        builder.append("\nSubject {");
        builder.append(" id: "+id);
        builder.append(" ,name: "+name);
        builder.append(" }");

        return builder.toString();
    }
}
